import com.asprise.ocr.Ocr;
import com.sun.jna.Platform;
import lombok.extern.slf4j.Slf4j;
import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;

import java.io.*;
import java.util.Date;

/**
 *
 */
@Slf4j
public class ImgDoOCR {



    public static String parse(String url) {

        return "";
    }

    /**
     * 写入外链文件
     * @param url  外链路径
     */
    public static String writeFile(String url,String end) {
        String urlStr = null;
        try{
            HttpClient client = new HttpClient();
            GetMethod get = new GetMethod(url);
            String imageUrl = (ImgDoOCR.class.getResource("/").getPath()+(Long)new Date().getTime()+end).substring(1);
            log.info(imageUrl);
            File storeFile = new File(imageUrl);
            if(!storeFile.exists()){
                storeFile.createNewFile();
            }
            FileOutputStream output = null;

            client.executeMethod(get);
            output = new FileOutputStream(storeFile);
            output.write(get.getResponseBody());
            output.close();
            urlStr = storeFile.getPath();
        } catch (HttpException e) {
            e.printStackTrace();
        }catch (FileNotFoundException e){
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }
        return urlStr;
    }


}
